from django.shortcuts import render
from django.http import HttpResponse,JsonResponse
#import json
import datetime
from .utility.genStructure import generateImg

def index(request):
    #return HttpResponse("Hello, world. You're at the fanyi index.")
    return render(request,'fanyi/templates/index.html')

def fanyiEn(request):
    resp = {'codeType': 500, 'detail': '','src':''}
    if request.method == 'POST':
        sentenceContent = request.POST.get('sentence')
        imgSrc = generateImg(getDatetimeNow(),sentenceContent)
        resp = {'codeType': 100, 'detail': sentenceContent,'src':imgSrc,'wordList':''}
    #return HttpResponse(json.dumps(resp), content_type="application/json")
    return JsonResponse(resp)

def fanyiJp(request):
    return render(request,'fanyi/templates/index.html')

def getDatetimeNow():
    curr_time = datetime.datetime.now()
    return str(curr_time).replace(':','').replace('.','')